package com.tus.storage;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface FileStorage {

    /**
     * 创建文件
     *
     * @param uploadId
     * @param fileSize
     * @return
     * @throws IOException
     */
    String createFile(String uploadId, long fileSize) throws IOException;

    /**
     * 创建文件
     *
     * @param uploadId
     * @param fileName
     * @param fileSize
     * @return
     * @throws IOException
     */
    String createFile(String uploadId, String fileName, long fileSize) throws IOException;


    /**
     * 创建分片目录
     *
     * @param uploadId
     * @return
     * @throws IOException
     */
    String createChunkDirectory(String uploadId) throws IOException;


    /**
     * 写入分片文件
     *
     * @param uploadId
     * @param filename
     * @param data
     * @return
     * @throws IOException
     */
    String writeChunkFile(String uploadId, String filename, byte[] data) throws IOException;


    /**
     * 获取分片大小
     *
     * @param chunkPath
     * @return
     */
    long getChunkSize(String chunkPath);


    /**
     * 合并分片（按 offset 排序）
     *
     * @param chunkPaths
     * @param finalPath
     * @param chunkOffsets
     * @throws IOException
     */
    void mergeChunks(List<String> chunkPaths, String finalPath, Map<String, Long> chunkOffsets) throws IOException;


    /**
     * 清理分片目录
     *
     * @param uploadId
     * @throws IOException
     */
    void cleanupChunks(String uploadId) throws IOException;

    /**
     * 删除文件
     *
     * @param path
     * @throws IOException
     */
    void deleteFile(String path) throws IOException;

    /**
     * 写分片
     *
     * @param filePathStr
     * @param offset
     * @param data
     * @throws IOException
     */
    void writeChunk(String filePathStr, long offset, byte[] data) throws IOException;

    /**
     * 获取文件
     *
     * @param filePath
     * @return
     */
    File getFile(String filePath);
}